Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
Is it possible to update a column(automatically) with "current_timestamp" in PostgreSQL using "Generated Columns"?

Is it possible to update a column (automatically) with "current_timestamp" in PostgreSQL using "Generated Columns", whenever the row gets update?

At present, I am using trigger to update the audit field last_update_date. But I am planning to switch to generated column

ALTER TABLE test ADD COLUMN last_update_date timestamp without time zone 
GENERATED ALWAYS AS (current_timestamp) STORED;

Getting error while altering column

ERROR: generation expression is not immutable
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

No, that won't work, for the reason specified in the error.

Functions used in generated columns must always return the same value for the same arguments, that is, depend on nothing but the current database row. current_timestamp obviously is not of that kind.

If PostgreSQL did allow such functions to be used in generated columns, then the value of the column would change if the database is restored from a pg_dump, for example.

Use a BEFORE INSERT OR UPDATE trigger for this purpose.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda